package com.cf.r952_ak;

import java.io.*;

public class a {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int t = Integer.parseInt(br.readLine());
        while (t-- > 0) {
            String[] s = br.readLine().split(" ");
            char[] s1 = s[0].toCharArray();
            char[] s2 = s[1].toCharArray();
            char tmp = s1[0];
            s1[0] = s2[0];
            s2[0] = tmp;
            out.println(new String(s1) + " " + new String(s2));
        }
        out.close();
        out.close();
        br.close();
    }
}
